package com.superlc.ssm.core.common.annotation;

import com.superlc.ssm.modular.sys.model.UserInfo;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

/**
 * @author super
 */
@Component
public class UserSessionArgsResolves implements HandlerMethodArgumentResolver {
    @Override
    public boolean supportsParameter(MethodParameter methodParameter) {
        //System.out.println("判断执行自定义参数解析方法");
        return methodParameter.hasMethodAnnotation(LoginRequired.class);
    }

    @Override
    public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
//        System.out.println(methodParameter.toString());
//        System.out.println("执行自定义参数解析方法！");
        return new UserInfo();
        ///获取请求参数赋值给user对象最后返回给目标方法的形参
    }
}
